package com.example.leonard.service.impl;

import com.alibaba.fastjson.JSON;
import com.example.leonard.core.domain.Customer;
import com.example.leonard.mapper.CustomerMapper;
import com.example.leonard.service.ICustomerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.regex.Pattern;

/**
 * @auther heyang
 * @date 2020/11/4 21:01
 */
@Service
public class ICustomerServiceImpl implements ICustomerService {
    @Autowired
    private CustomerMapper customerMapper;
    private static final Logger LOGGER = LoggerFactory.getLogger(ICustomerServiceImpl.class);
    //用来验证电话号码的正则表达式
    private static final String REGEXP = "^((13[0-9])|(14[5,7,9])|(15[0-3,5-9])|(166)|(17[3,5,6,7,8])" +
            "|(18[0-9])|(19[8,9]))\\d{8}$";

    @Override
    public Customer selectCustomerById(Long id) {
        try {
            Customer customer = customerMapper.selectByPrimaryKey(id);
            LOGGER.info("customer的信息->{}", JSON.toJSONString(customer));
            Pattern compile = Pattern.compile(REGEXP);
            boolean matches = compile.matcher("138").matches();
            LOGGER.info("返回结果->{}", matches);
            return customer;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public List<Customer> selectAll() {
        List<Customer> customers = customerMapper.selectAll();
        return customers;
    }
}
